//
//  RXMainViewController.swift
//  weibo
//
//  Created by uncle-R on 15/12/15.
//  Copyright © 2015年 uncle-R. All rights reserved.
//

import UIKit

class RXMainViewController: UITabBarController {

    override func viewDidLoad() {
        
        super.viewDidLoad()
        //设置tabBar图片文字颜色.
        self.tabBar.tintColor = UIColor.orangeColor()
        setValue(RXTabBar(), forKey: "tabBar")
        addViewController()
  
    }
    /**
     添加子控制器
     */
    func addViewController(){
        
        let home = RXHomeViewController()
        addNavcontroller(home, text: "首页", UIImagename:"tabbar_home" )
       
        let message = RXMessageViewController()
       addNavcontroller(message, text: "消息中心", UIImagename: "tabbar_message_center")
        
        let discover = RXDiscoverController()
        addNavcontroller(discover, text: "发现", UIImagename: "tabbar_discover")

        let profile = RXProfileViewController()
        addNavcontroller(profile, text: "我", UIImagename: "tabbar_profile")
        
    }
    
    /**
     包装导航栏控制器
     */
    func addNavcontroller(vc: UIViewController,text: String,UIImagename: String){
        
        
        let nav = UINavigationController(rootViewController: vc)
        vc.title = text
        let selectIamgeName = UIImagename+"_highlighted"
        //设置图片
         nav.tabBarItem.image = UIImage(named: UIImagename)
        
        nav.tabBarItem.selectedImage = UIImage(named:selectIamgeName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        addChildViewController(nav)
    
        nav.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: UIControlState.Selected)
        
    }
//    
//    func tabBarController(tabBarController: UITabBarController, didSelectViewController viewController: UIViewController) {
//        
//        let animated = CABasicAnimation(keyPath: "scale.x")
//        animated.fromValue = 0.8
//        animated.toValue = 1
//        animated.duration = 1.0
//        viewController.view.layer.addAnimation(animated, forKey: nil)
//    }

}
